package com.gxa.modules.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gxa.common.constants.Constants;
import com.gxa.modules.dto.AnnouncementDTO;
import com.gxa.modules.entity.CrmAnnouncement;
import com.gxa.modules.mapper.AnnouncementMapper;
import com.gxa.modules.service.AnnouncementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Transactional
@Service
public class AnnouncementServiceImpl implements AnnouncementService {


    @Autowired
    private AnnouncementMapper announcementMapper;

    @Override
    public List<CrmAnnouncement> showAll(AnnouncementDTO announcementDTO) {
        QueryWrapper queryWrapper=new QueryWrapper();
        if(announcementDTO.getAnnouncementType()!=null){
            queryWrapper.eq("announcement_type",announcementDTO.getAnnouncementType());
        }

        return announcementMapper.selectPage(new Page(announcementDTO.getCurrentPage(),announcementDTO.getPageSize()),queryWrapper).getRecords();
    }

    @Override
    public int addAnnouncement(CrmAnnouncement crmAnnouncement) {
        return announcementMapper.insert(crmAnnouncement);
    }

    @Override
    public int updateannouncement(CrmAnnouncement crmAnnouncement) {
        return announcementMapper.updateById(crmAnnouncement);
    }

    @Override
    public int deleteannouncement(Integer id) {
        return announcementMapper.deleteById(id);
    }
}
